---
import BlogPostLayout from "@/layouts/BlogPost.astro";
import { getCollection, type CollectionEntry } from "astro:content";

export async function getStaticPaths() {
  const posts = await getCollection("blog");
  return posts.map((post) => ({
    params: { slug: post.slug },
    props: post,
  }));
}

type Props = CollectionEntry<"blog">;

const post = Astro.props;
const slug = Astro.params.slug;
const { Content } = await post.render();

if (!slug || !post) {
  return new Response(null, {
    status: 404,
    statusText: "Not found",
  });
}
---

<BlogPostLayout {...post}>
  <Content />
</BlogPostLayout>
